package org.gnuhpc.adapter;

import org.gnuhpc.R;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class EfficientAdapter extends BaseAdapter {
	private LayoutInflater mInflater;  
	String[]col1 = null;
	String[]col2 = null;
	private static final String LOG_TAG = "ShowLocation";
	
	public EfficientAdapter(Context context,String[] col1, String[] col2) {
		mInflater = LayoutInflater.from(context);
		this.col1 = col1;
		this.col2 = col2;
	}
	
	public int getCount() {		
		return col1.length;
	}

	public Object getItem(int position) {		
		return position;
	}

	public long getItemId(int position) {	
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		Viewholder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.listview, null);
			holder = new Viewholder();
			holder.text1 = (TextView)convertView.findViewById(R.id.TextView01);
			holder.text2 = (TextView)convertView.findViewById(R.id.TextView02);
			convertView.setTag(holder);
			Log.d(LOG_TAG, "position is" + position);
			convertView.setBackgroundColor((position % 2)==1?Color.WHITE:Color.LTGRAY);
		}
		else {
			holder = (Viewholder) convertView.getTag();  
		}
		holder.text1.setText(col1[position]);
		holder.text2.setText(col2[position]);
		return convertView;		
	}
	
	static class Viewholder{
		TextView text1;
		TextView text2;
	}
}
